import os

import pymysql
import pytest


from config.config import DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD, SQL1, SQL2, SQL3


@pytest.fixture(scope="session",autouse=True)
def destroy_data():

    yield
    sqls = [SQL1, SQL2, SQL3]
    conn = pymysql.connect(

       # host=DB_HOST,
       # port=DB_PORT,
       # database=DB_NAME,
       # user=DB_USER,
       # password=DB_PASSWORD,
        **eval(os.environ["DB"]),
       charset="utf8",
       autocommit=True   # 提交
    )
# 桥 + 护
    cur = conn.cursor()

    for sql in sqls:
        cur.execute(sql)  # 执行之后必须得有个提交

# 关闭资源
    cur.close()
    conn.close()

